﻿using Aspose.Cells;
using Bentley.GeometryNET.Common;
using CheccCoverplateCulvertAssemble.Common;
using CheccCoverplateCulvertAssemble.Conmmon;
using CheccCoverplateCulvertAssemble.Entity;
using CheccCoverplateCulvertAssemble.Tools;
using CheccTexturePropertyGive;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using 平交口设计.solid;
using static Bentley.CIMNET.CIMGeometry.Solid.SolidUtil;
using static Bentley.CIMNET.CIMGeometry.Solid.SolidUtil.Modify;
using static CheccTexturePropertyGive.SetCoverCulvertTexture;

namespace CheccCoverplateCulvertAssemble.Operation
{
    internal class ReplaceMent : ConstructingEntity
    {
        public ReplaceMent(BasicConstructor basicConstructor, CulvertType culvertType, ConstructionMethod constructionMethod, CulvertComponentType culvertComponentType) : base(basicConstructor, culvertType, constructionMethod, culvertComponentType)
        {
        }

        public override void CreateEntityModel()
        {
            //真实位置
            DTransform3d dTransform = new DTransform3d(this.dMatrix3D);
            dTransform.Translation = this.placeDpoint3d * GeneralBank.UorToMeters;
            TransformInfo dTransFormInfo = new TransformInfo(dTransform);

            if (this.basicType == BasicType.UnitaryBasic)   //整体式
            {
                var objParameter = GetUorCoverParameter();
                List<Element> elements = CreateCushion(
                    objParameter.leftLateralAngle,
                    objParameter.rightLateralAngle,
                    objParameter.clearSpan + objParameter.standPly * 2 + objParameter.basicsEdge * 2, 
                    objParameter.baseSlope, 
                    this.keyValuePairs
                    );
                DPoint3d movePoint3d = new DPoint3d(0, 0, -(objParameter.piecePly + objParameter.clearHeight + objParameter.basicsPly)) * GeneralBank.UorToMeters;
                DTransform3d trans = DTransform3d.Identity;
                trans.Translation = movePoint3d;
                TransformInfo transformInfo = new TransformInfo(trans);

                foreach (Element ele in elements)
                {
                    ele.ApplyTransform(transformInfo);
                    ele.ApplyTransform(dTransFormInfo);
                    ele.ReplaceInModel(ele);
                    SetCoverCulvertTexture setCoverCulvertTexture = new SetCoverCulvertTexture();
                    setCoverCulvertTexture.CoverCulvertTexture(ele, CoverCulvertConstruction.Replacement);
                    CommonData.Instance.ElementIds.Add(ele.ElementId.ToString());
                }
            }
            else if (this.basicType == BasicType.SeparatingBasic) //分离式
            {
                var objParameter = GetUorCoverParameter2();
                List<Element> elements = CreateCushionSeparating(
                    objParameter.leftLateralAngle,
                    objParameter.rightLateralAngle,
                    objParameter.clearSpan + objParameter.standPly * 2 + objParameter.basicsEdge * 2,
                    objParameter.baseSlope,
                    objParameter.clearSpan - (objParameter.basicsWidth * 2 - objParameter.standPly * 2 - objParameter.basicsEdge * 2) ,
                    objParameter.basicsPly,
                    this.keyValuePairs
                    );
                DPoint3d movePoint3d = new DPoint3d(0, 0, -(objParameter.piecePly + objParameter.clearHeight + objParameter.basicsPly)) * GeneralBank.UorToMeters;
                DTransform3d trans = DTransform3d.Identity;
                trans.Translation = movePoint3d;
                TransformInfo transformInfo = new TransformInfo(trans);
                foreach (Element ele in elements)
                {
                    ele.ApplyTransform(transformInfo);
                    ele.ApplyTransform(dTransFormInfo);
                    ele.ReplaceInModel(ele);
                    SetCoverCulvertTexture setCoverCulvertTexture = new SetCoverCulvertTexture();
                    setCoverCulvertTexture.CoverCulvertTexture(ele, CoverCulvertConstruction.Replacement);
                    CommonData.Instance.ElementIds.Add(ele.ElementId.ToString());
                }
            }
        }

        /// <summary>
        /// 构建分离式换填实体
        /// </summary>
        /// <param name="leftLateralAngle">左偏置角</param>
        /// <param name="rightLateralAngle">右偏置角</param>
        /// <param name="culvertWidth">涵身宽度(m)</param>
        /// <param name="culvertSlope">涵底坡度(3%换算0.03)</param>
        /// <param name="topWidth">顶部换填宽度</param>
        /// <param name="basicsPly">基础厚度</param>
        /// <param name="keyValuePairs">换填数据</param>
        private List<Element> CreateCushionSeparating(double leftLateralAngle, double rightLateralAngle, double culvertWidth, double culvertSlope,double topWidth, double basicsPly, Dictionary<string, ReplaceMentEntity> keyValuePairs)
        {
            List<Element> solidList = new List<Element>();
            //逐层记录襟边之和
            double basicsEdge = 0;
            //逐层记录换填深度之和
            double fillDepth = 0;
            //逐层记录坡比换算宽度之和
            double slopeWidthSum = 0;

            foreach (KeyValuePair<string, ReplaceMentEntity> kvp in keyValuePairs)
            {
                ReplaceMentEntity replaceMent = kvp.Value;
                basicsEdge += replaceMent.ExchangeFillEdge * 0.01;
                slopeWidthSum += (replaceMent.ExchangeFillSlopeRatio * (replaceMent.ExchangeFillDepth + replaceMent.ExchangeFillThickenDepth)) * 0.01;
            }
            //左偏置长度
            double leftLateralOffset = Math.Abs((culvertWidth / 2 + basicsEdge + slopeWidthSum) * Math.Tan((90 - leftLateralAngle) * Math.PI / 180));
            //右偏置长度
            double rightLateralOffset = Math.Abs((culvertWidth / 2 + basicsEdge + slopeWidthSum) * Math.Tan((90 - rightLateralAngle) * Math.PI / 180));
            //换填最底层宽度
            double cushionWidth = culvertWidth / 2 + basicsEdge + slopeWidthSum;

            basicsEdge = 0;
            slopeWidthSum = 0;
            int index = 0;
            foreach (KeyValuePair<string, ReplaceMentEntity> kvp in keyValuePairs)
            {
                index++;
                ReplaceMentEntity replaceMent = kvp.Value;
                basicsEdge += replaceMent.ExchangeFillEdge * 0.01;
                //换填坡比对应宽度
                double slopWidth = (replaceMent.ExchangeFillSlopeRatio * (replaceMent.ExchangeFillDepth + replaceMent.ExchangeFillThickenDepth)) * 0.01;
                DPoint3d[] points = null;
                if (index == 1)
                {
                    points = new DPoint3d[]
                    {
                        new DPoint3d(0, -topWidth / 2 , -(fillDepth - basicsPly)) * GeneralBank.UorToMeters,
                        new DPoint3d(0, -topWidth / 2 , -fillDepth) * GeneralBank.UorToMeters,
                        new DPoint3d(0, -(culvertWidth / 2 + basicsEdge + slopeWidthSum), -fillDepth) * GeneralBank.UorToMeters,
                        new DPoint3d(0, -(culvertWidth / 2 + basicsEdge + slopWidth + slopeWidthSum), -(fillDepth + replaceMent.ExchangeFillDepth * 0.01 + replaceMent.ExchangeFillThickenDepth * 0.01)) * GeneralBank.UorToMeters,
                        new DPoint3d(0, (culvertWidth / 2 + basicsEdge + slopWidth + slopeWidthSum), -(fillDepth  + replaceMent.ExchangeFillDepth * 0.01 + replaceMent.ExchangeFillThickenDepth * 0.01)) * GeneralBank.UorToMeters,
                        new DPoint3d(0, (culvertWidth / 2 + basicsEdge + slopeWidthSum), -fillDepth) * GeneralBank.UorToMeters,
                        new DPoint3d(0, topWidth / 2 , -fillDepth) * GeneralBank.UorToMeters,
                        new DPoint3d(0, topWidth / 2 , -(fillDepth - basicsPly)) * GeneralBank.UorToMeters,
                        new DPoint3d(0, -topWidth / 2 , -(fillDepth - basicsPly)) * GeneralBank.UorToMeters,
                    };
                }
                else
                {
                    points = new DPoint3d[]
                    {
                        new DPoint3d(0, -(culvertWidth / 2 + basicsEdge + slopeWidthSum), -fillDepth) * GeneralBank.UorToMeters,
                        new DPoint3d(0, -(culvertWidth / 2 + basicsEdge + slopWidth + slopeWidthSum), -(fillDepth + replaceMent.ExchangeFillDepth * 0.01 + replaceMent.ExchangeFillThickenDepth * 0.01)) * GeneralBank.UorToMeters,
                        new DPoint3d(0, (culvertWidth / 2 + basicsEdge + slopWidth + slopeWidthSum), -(fillDepth + replaceMent.ExchangeFillDepth * 0.01 + replaceMent.ExchangeFillThickenDepth * 0.01)) * GeneralBank.UorToMeters,
                        new DPoint3d(0, (culvertWidth / 2 + basicsEdge + slopeWidthSum), -fillDepth) * GeneralBank.UorToMeters,
                        new DPoint3d(0, -(culvertWidth / 2 + basicsEdge + slopeWidthSum), -fillDepth) * GeneralBank.UorToMeters,
                    };
                }

                ShapeElement shapeElement = new ShapeElement(GeneralBank.ActiveDgnModel, null, points);
                CurveVector secCur = shapeElement.GetCurveVector();
                LineElement lineElement = GetSlopLinee(DPoint3d.Zero, replaceMent.ExchangeFillLength + leftLateralOffset + rightLateralOffset, culvertSlope, out DPoint3d slopeEndPT);
                SolidKernelEntity solidKernel = CreateBodyFromSweep(lineElement.GetCurveVector(), secCur, GeneralBank.ActiveDgnModel);

                DPoint3d movePoint3d = new DPoint3d(-leftLateralOffset, 0, -(leftLateralOffset * culvertSlope)) * GeneralBank.UorToMeters;
                DTransform3d trans = DTransform3d.Identity;
                trans.Translation = movePoint3d;
                TransformBody(ref solidKernel, trans);

                SolidKernelEntity cutSolid = CutCushion(solidKernel, leftLateralAngle, rightLateralAngle, leftLateralOffset, rightLateralOffset, replaceMent.ExchangeFillLength, cushionWidth, 0);

                //最后一层是否加厚
                if (index == keyValuePairs.Count)
                {
                    if (replaceMent.ExchangeFillThickenDepth > 0)
                    {
                        DPoint3d[] pts =
                        {
                            new DPoint3d(0,-(culvertWidth/ 2 + basicsEdge + slopWidth + slopeWidthSum),-(fillDepth + replaceMent.ExchangeFillDepth * 0.01 +  replaceMent.ExchangeFillThickenDepth * 0.01))* GeneralBank.UorToMeters,
                            new DPoint3d(0,(culvertWidth/ 2 + basicsEdge + slopWidth + slopeWidthSum),-(fillDepth + replaceMent.ExchangeFillDepth * 0.01 +  replaceMent.ExchangeFillThickenDepth * 0.01))* GeneralBank.UorToMeters,
                            new DPoint3d(0,(culvertWidth/ 2 + basicsEdge + slopWidth + slopeWidthSum),-(fillDepth + replaceMent.ExchangeFillDepth * 0.01))* GeneralBank.UorToMeters,
                            new DPoint3d(0,-(culvertWidth/ 2 + basicsEdge + slopWidth + slopeWidthSum),-(fillDepth + replaceMent.ExchangeFillDepth * 0.01))* GeneralBank.UorToMeters,
                            new DPoint3d(0,-(culvertWidth/ 2 + basicsEdge + slopWidth + slopeWidthSum),-(fillDepth + replaceMent.ExchangeFillDepth * 0.01 +  replaceMent.ExchangeFillThickenDepth * 0.01))* GeneralBank.UorToMeters,
                        };
                        cutSolid = CutFillDepthCushion(
                            cutSolid, 
                            leftLateralAngle, 
                            rightLateralAngle,
                            leftLateralOffset, 
                            rightLateralOffset, 
                            replaceMent.ExchangeFillLength,
                            replaceMent.ExchangeFillThickenLength * 0.01,
                            cushionWidth,
                            culvertSlope, 
                            pts
                            );
                    }
                }
                Convert1.BodyToElement(out Element cutResultElement, cutSolid, null, GeneralBank.ActiveDgnModel);
                cutResultElement.AddToModel();
                slopeWidthSum += slopWidth;
                fillDepth += replaceMent.ExchangeFillDepth * 0.01;
                solidList.Add(cutResultElement);

                //属性赋予
                SetCoverCulvertECProperty setCoverCulvertECProperty = new SetCoverCulvertECProperty();
                setCoverCulvertECProperty.SetReplacementECProperty(
                    cutResultElement,
                    replaceMent.ExchangeFillDepth.ToString(),
                    replaceMent.ExchangeFillEdge.ToString(),
                    replaceMent.ExchangeFillSlopeRatio.ToString(),
                    replaceMent.ExchangeFillMaterial,
                    replaceMent.ExchangeFillThickenLength.ToString(),
                    replaceMent.ExchangeFillThickenDepth.ToString()
                    );
            }
            return solidList;
        }


        /// <summary>
        /// 构建整体式换填实体
        /// </summary>
        /// <param name="leftLateralAngle">左偏置角</param>
        /// <param name="rightLateralAngle">右偏置角</param>
        /// <param name="culvertWidth">涵身宽度(m)</param>
        /// <param name="culvertSlope">涵底坡度(3%换算0.03)</param>
        /// <param name="keyValuePairs">换填数据</param>
        private List<Element> CreateCushion(double leftLateralAngle,double rightLateralAngle,double culvertWidth,double culvertSlope,  Dictionary<string, ReplaceMentEntity> keyValuePairs)
        {
            List<Element> solidList = new List<Element>();
            //逐层记录襟边之和
            double basicsEdge = 0;
            //逐层记录换填深度之和
            double fillDepth = 0;
            //逐层记录坡比换算宽度之和
            double slopeWidthSum = 0;

            foreach (KeyValuePair<string, ReplaceMentEntity> kvp in keyValuePairs)
            {
                ReplaceMentEntity replaceMent = kvp.Value;
                basicsEdge += replaceMent.ExchangeFillEdge * 0.01;
                slopeWidthSum += (replaceMent.ExchangeFillSlopeRatio * (replaceMent.ExchangeFillDepth + replaceMent.ExchangeFillThickenDepth)) * 0.01;
            }
            //左偏置长度
            double leftLateralOffset = Math.Abs((culvertWidth / 2 + basicsEdge + slopeWidthSum) * Math.Tan((90 - leftLateralAngle) * Math.PI / 180));
            //右偏置长度
            double rightLateralOffset = Math.Abs((culvertWidth / 2 + basicsEdge + slopeWidthSum) * Math.Tan((90 - rightLateralAngle) * Math.PI / 180));
            //换填最底层宽度
            double cushionWidth = culvertWidth / 2 + basicsEdge + slopeWidthSum;

            basicsEdge = 0;
            slopeWidthSum = 0;
            int index  = 0;
            foreach (KeyValuePair<string, ReplaceMentEntity> kvp in keyValuePairs)
            {
                index++;
                ReplaceMentEntity replaceMent = kvp.Value;
                basicsEdge += replaceMent.ExchangeFillEdge * 0.01;
                //换填坡比对应宽度
                double slopWidth = (replaceMent.ExchangeFillSlopeRatio * (replaceMent.ExchangeFillDepth + replaceMent.ExchangeFillThickenDepth)) * 0.01;
                DPoint3d[] points =
                {
                    new DPoint3d(0,-(culvertWidth/ 2 + basicsEdge + slopeWidthSum ),- fillDepth)* GeneralBank.UorToMeters,
                    new DPoint3d(0,-(culvertWidth/ 2 + basicsEdge + slopWidth + slopeWidthSum),-(fillDepth + replaceMent.ExchangeFillDepth * 0.01 +  replaceMent.ExchangeFillThickenDepth * 0.01))* GeneralBank.UorToMeters,
                    new DPoint3d(0,(culvertWidth/ 2 + basicsEdge + slopWidth + slopeWidthSum),-(fillDepth + replaceMent.ExchangeFillDepth * 0.01 +  replaceMent.ExchangeFillThickenDepth * 0.01))* GeneralBank.UorToMeters,
                    new DPoint3d(0,(culvertWidth/ 2 + basicsEdge + slopeWidthSum),- fillDepth)* GeneralBank.UorToMeters,
                    new DPoint3d(0,-(culvertWidth/ 2 + basicsEdge + slopeWidthSum),- fillDepth)* GeneralBank.UorToMeters,
                };

                ShapeElement shapeElement = new ShapeElement(GeneralBank.ActiveDgnModel, null, points);
                CurveVector secCur = shapeElement.GetCurveVector();
                LineElement lineElement = GetSlopLinee(DPoint3d.Zero, replaceMent.ExchangeFillLength + leftLateralOffset + rightLateralOffset, culvertSlope, out DPoint3d slopeEndPT);
                SolidKernelEntity solidKernel = CreateBodyFromSweep(lineElement.GetCurveVector(), secCur, GeneralBank.ActiveDgnModel);

                DPoint3d movePoint3d = new DPoint3d(-leftLateralOffset, 0, -(leftLateralOffset * culvertSlope)) * GeneralBank.UorToMeters;
                DTransform3d trans = DTransform3d.Identity;
                trans.Translation = movePoint3d;
                TransformBody(ref solidKernel, trans);

                SolidKernelEntity cutSolid = CutCushion(solidKernel, leftLateralAngle, rightLateralAngle, leftLateralOffset, rightLateralOffset, replaceMent.ExchangeFillLength, cushionWidth,0);
                
                //最后一层是否加厚
                if (index == keyValuePairs.Count)
                {
                    if (replaceMent.ExchangeFillThickenDepth > 0) 
                    {
                        DPoint3d[] pts =
                        {
                            new DPoint3d(0,-(culvertWidth/ 2 + basicsEdge + slopWidth + slopeWidthSum),-(fillDepth + replaceMent.ExchangeFillDepth * 0.01 +  replaceMent.ExchangeFillThickenDepth * 0.01))* GeneralBank.UorToMeters,
                            new DPoint3d(0,(culvertWidth/ 2 + basicsEdge + slopWidth + slopeWidthSum),-(fillDepth + replaceMent.ExchangeFillDepth * 0.01 +  replaceMent.ExchangeFillThickenDepth * 0.01))* GeneralBank.UorToMeters,
                            new DPoint3d(0,(culvertWidth/ 2 + basicsEdge + slopWidth + slopeWidthSum),-(fillDepth + replaceMent.ExchangeFillDepth * 0.01))* GeneralBank.UorToMeters,
                            new DPoint3d(0,-(culvertWidth/ 2 + basicsEdge + slopWidth + slopeWidthSum),-(fillDepth + replaceMent.ExchangeFillDepth * 0.01))* GeneralBank.UorToMeters,
                            new DPoint3d(0,-(culvertWidth/ 2 + basicsEdge + slopWidth + slopeWidthSum),-(fillDepth + replaceMent.ExchangeFillDepth * 0.01 +  replaceMent.ExchangeFillThickenDepth * 0.01))* GeneralBank.UorToMeters,
                        };
                        cutSolid = CutFillDepthCushion(
                            cutSolid, 
                            leftLateralAngle, 
                            rightLateralAngle, 
                            leftLateralOffset, 
                            rightLateralOffset, 
                            replaceMent.ExchangeFillLength, 
                            replaceMent.ExchangeFillThickenLength * 0.01, 
                            cushionWidth, 
                            culvertSlope, 
                            pts
                            );
                    }
                }
                Convert1.BodyToElement(out Element cutResultElement, cutSolid, null, GeneralBank.ActiveDgnModel);
                cutResultElement.AddToModel();
                slopeWidthSum += slopWidth;
                fillDepth += replaceMent.ExchangeFillDepth * 0.01;
                solidList.Add(cutResultElement);

                //属性赋予
                SetCoverCulvertECProperty setCoverCulvertECProperty = new SetCoverCulvertECProperty();
                setCoverCulvertECProperty.SetReplacementECProperty(
                    cutResultElement,
                    replaceMent.ExchangeFillDepth.ToString(),
                    replaceMent.ExchangeFillEdge.ToString(), 
                    replaceMent.ExchangeFillSlopeRatio.ToString(), 
                    replaceMent.ExchangeFillMaterial, 
                    replaceMent.ExchangeFillThickenLength.ToString(), 
                    replaceMent.ExchangeFillThickenDepth.ToString()
                    );
                CheccCoverplateCulvertAssemble.FormColl.Assemble.SetTableData("涵台换填", kvp.Key, "", SetCoverCulvertECProperty.GetVolume(cutResultElement, Bentley.MstnPlatformNET.InteropServices.Utilities.ComApp), "m³");
            }
            return solidList;
        }


        private SolidKernelEntity CutCushion(SolidKernelEntity solidKernel ,double leftLateralAngle, double rightLateralAngle,double leftLateralOffset, double rightLateralOffset,double exchangeFillLength, double cutWidth ,double offsetLen)
        {
            LineElement cutLine = null;
            CurveVector cutLinePath = null;
            //左侧剪切
            if (leftLateralAngle < 90)
            {
                cutLine = new LineElement(GeneralBank.ActiveDgnModel, null, new DSegment3d(
                    new DPoint3d(-leftLateralOffset + offsetLen, -cutWidth, 0) * GeneralBank.UorToMeters,
                    new DPoint3d(leftLateralOffset + offsetLen, cutWidth, 0) * GeneralBank.UorToMeters));
            }
            else
            {
                cutLine = new LineElement(GeneralBank.ActiveDgnModel, null, new DSegment3d(
                    new DPoint3d(leftLateralOffset + offsetLen, -cutWidth, 0) * GeneralBank.UorToMeters,
                    new DPoint3d(-leftLateralOffset + offsetLen, cutWidth, 0) * GeneralBank.UorToMeters));
            }
            cutLinePath = cutLine.GetCurveVector();
            Bentley.CIMNET.CIMGeometry.Solid.SolidUtil.Modify.CutSolidsWithCurves(out SolidKernelEntity[] solidKernels, solidKernel, cutLinePath, SolidCutMethod.Split, SolidCutDirection.Both, SolidCutMode.Through, 0);
            if(solidKernels != null) solidKernel = solidKernels[0];
            
            cutLine = null;
            //右侧剪切
            if (rightLateralAngle < 90)
            {
                cutLine = new LineElement(GeneralBank.ActiveDgnModel, null, new DSegment3d(
                        new DPoint3d(exchangeFillLength + rightLateralOffset - offsetLen, cutWidth, 0) * GeneralBank.UorToMeters,
                        new DPoint3d(exchangeFillLength - rightLateralOffset - offsetLen, -cutWidth, 0) * GeneralBank.UorToMeters));
            }
            else
            {
                cutLine = new LineElement(GeneralBank.ActiveDgnModel, null, new DSegment3d(
                        new DPoint3d(exchangeFillLength - rightLateralOffset - offsetLen, cutWidth, 0) * GeneralBank.UorToMeters,
                        new DPoint3d(exchangeFillLength + rightLateralOffset - offsetLen, -cutWidth, 0) * GeneralBank.UorToMeters));
            }
            cutLinePath = cutLine.GetCurveVector();
            Bentley.CIMNET.CIMGeometry.Solid.SolidUtil.Modify.CutSolidsWithCurves(out SolidKernelEntity[] resultSolids, solidKernel, cutLinePath, SolidCutMethod.Split, SolidCutDirection.Both, SolidCutMode.Through, 0);
            if (resultSolids != null) solidKernel = resultSolids[0];
            return solidKernel;
        }

        private SolidKernelEntity CutFillDepthCushion(SolidKernelEntity targetSolid, double leftLateralAngle, double rightLateralAngle, double leftLateralOffset, double rightLateralOffset, 
            double exchangeFillLength,double exchangeFillThickenLength,  double cutWidth ,double culvertSlope, DPoint3d[] points)
        {
            ShapeElement shapeElement = new ShapeElement(GeneralBank.ActiveDgnModel, null, points);
            CurveVector secCur = shapeElement.GetCurveVector();
            LineElement lineElement = GetSlopLinee(DPoint3d.Zero, exchangeFillLength + leftLateralOffset + rightLateralOffset, culvertSlope, out DPoint3d slopeEndPT);
            SolidKernelEntity solidKernel = CreateBodyFromSweep(lineElement.GetCurveVector(), secCur, GeneralBank.ActiveDgnModel);
            DPoint3d movePoint3d = new DPoint3d(-leftLateralOffset, 0, -(leftLateralOffset * culvertSlope)) * GeneralBank.UorToMeters;
            DTransform3d trans = DTransform3d.Identity;
            trans.Translation = movePoint3d;
            TransformBody(ref solidKernel, trans);

            //Convert1.BodyToElement(out Element cutResultElement, solidKernel, null, GeneralBank.ActiveDgnModel);
            //cutResultElement.AddToModel();

            SolidKernelEntity cutSolid = CutCushion(solidKernel, leftLateralAngle, rightLateralAngle, leftLateralOffset, rightLateralOffset, exchangeFillLength , cutWidth, exchangeFillThickenLength);
            SolidKernelEntity[] solidKernels =new SolidKernelEntity[] { cutSolid };
            BodyBooleanSubtract(ref targetSolid, ref solidKernels, 1);
            return targetSolid;
        }


        public SolidKernelEntity CreateBodyFromSweep(CurveVector pathCur, CurveVector secCur, DgnModel modelRef)
        {
            pathCur.GetStartEnd(out DPoint3d startPt, out _, out DVector3d startTangent, out _);
            CurveVector secCur1 = secCur.Clone();
            BCIMNETGS.SolidUtil.Create.BodyFromSweep(out SolidKernelEntity entity, secCur1, pathCur, modelRef, false, true, false, null, null, null, null);
            return entity;
        }

        /// <summary>
        /// 基于dPoint3D点沿X轴绘制线
        /// </summary>
        /// <param name="boxCulvertLength">涵长水平距离</param>
        /// <param name="slop">坡度; (例如0.1就是10%的坡率)</param>
        /// <returns></returns>
        public LineElement GetSlopLinee(DPoint3d dPoint3D, double boxCulvertLength, double slop, out DPoint3d endPt)
        {
            double z = boxCulvertLength * slop;
            endPt = new DPoint3d(dPoint3D.X + boxCulvertLength, dPoint3D.Y, dPoint3D.Z + z) * GeneralBank.UorToMeters;
            return new LineElement(GeneralBank.ActiveDgnModel, null, new DSegment3d(dPoint3D * GeneralBank.UorToMeters, new DPoint3d(dPoint3D.X + boxCulvertLength, dPoint3D.Y, dPoint3D.Z + z) * GeneralBank.UorToMeters));
        }



        /// <summary>
        /// 获取整体式洞身构造参数
        /// </summary>
        /// <returns> 涵长,左偏角,右偏角,涵身沉降缝宽度,基础沉降缝宽度,涵底坡度, 净跨,净高,挡块高度,基础襟边,台身厚度,台身顶宽,底部倒角,基础厚度,净保护层</returns>
        /// 
        private (double basicsLength, double leftLateralAngle, double rightLateralAngle, double culvertGapWidth, double baseGapWidth, double baseSlope, double clearSpan, double clearHeight,
            double piecePly, double basicsEdge, double standPly, double standTopWidth, double bottomChamfer, double basicsPly, double protectiveLayer) GetUorCoverParameter()
        {
            double basicsLength = this.basicConstructor.BasicsLength / 100;
            double leftLateralAngle = this.basicConstructor.LeftLateralAngle;
            double rightLateralAngle = this.basicConstructor.RightLateralAngle;
            double culvertGapWidth = this.basicConstructor.CulvertGapWidth / 100;
            double baseGapWidth = this.basicConstructor.BaseGapWidth / 100;
            double baseSlope = this.basicConstructor.CulvertBaseSlope / 100;
            double clearSpan = this.basicConstructor.ClearSpan;
            double clearHeight = this.basicConstructor.ClearHeight;
            double piecePly = this.basicConstructor.PiecePly / 100;
            double basicsEdge = this.basicConstructor.BasicsEdge / 100;
            double standPly = this.basicConstructor.StandPly / 100;
            double standTopWidth = this.basicConstructor.StandTopWidth / 100;
            double bottomChamfer = this.basicConstructor.BottomChamfer / 100;
            double basicsPly = this.basicConstructor.BasicsPly / 100;
            double protectiveLayer = this.basicConstructor.ProtectiveLayer;
            return (basicsLength, leftLateralAngle, rightLateralAngle, culvertGapWidth, baseGapWidth, baseSlope, clearSpan, clearHeight, piecePly, basicsEdge, standPly, standTopWidth, bottomChamfer, basicsPly, protectiveLayer);
        }

        /// <summary>
        /// 获取分离式洞身构造参数
        /// </summary>
        /// <returns> 涵长,左偏角,右偏角,涵身沉降缝宽度,基础沉降缝宽度,涵底坡度, 净跨,净高,挡块高度,基础襟边,台身厚度,基础宽度,台身顶宽,基础厚度,净保护层</returns>
        /// 
        private (double basicsLength, double leftLateralAngle, double rightLateralAngle, double culvertGapWidth, double baseGapWidth, double baseSlope, double clearSpan, double clearHeight,
            double piecePly, double basicsEdge, double standPly, double basicsWidth, double standTopWidth, double basicsPly, double protectiveLayer) GetUorCoverParameter2()
        {
            double basicsLength = this.basicConstructor.BasicsLength / 100;
            double leftLateralAngle = this.basicConstructor.LeftLateralAngle;
            double rightLateralAngle = this.basicConstructor.RightLateralAngle;
            double culvertGapWidth = this.basicConstructor.CulvertGapWidth / 100;
            double baseGapWidth = this.basicConstructor.BaseGapWidth / 100;
            double baseSlope = this.basicConstructor.CulvertBaseSlope / 100;
            double clearSpan = this.basicConstructor.ClearSpan;
            double clearHeight = this.basicConstructor.ClearHeight;
            double piecePly = this.basicConstructor.PiecePly / 100;
            double basicsEdge = this.basicConstructor.BasicsEdge / 100;
            double standPly = this.basicConstructor.StandPly / 100;
            double basicsWidth = this.basicConstructor.BasicWidth / 100;
            double standTopWidth = this.basicConstructor.StandTopWidth / 100;
            double basicsPly = this.basicConstructor.BasicsPly / 100;
            double protectiveLayer = this.basicConstructor.ProtectiveLayer;
            return (basicsLength, leftLateralAngle, rightLateralAngle, culvertGapWidth, baseGapWidth, baseSlope, clearSpan, clearHeight, piecePly, basicsEdge, standPly, basicsWidth, standTopWidth, basicsPly, protectiveLayer);
        }

        public override void CreateElementECProperty(Element element, List<Tuple<string, CustomProperty.TypeKind, bool, bool>> tuples)
        {
            throw new NotImplementedException();
        }

        public override List<(string standardName, string standValue)> CreateStandardECProperty()
        {
            throw new NotImplementedException();
        }

        public override double GetVolumeOfElement(Element element)
        {
            throw new NotImplementedException();
        }

        public override void SaveStandardECProperty(IDgnECInstance dgnECInstanc)
        {
            throw new NotImplementedException();
        }

        public override void SetECInstanceValue(IDgnECInstance dgnECInstance, List<(string propertyName, string calculationBasis, string computationalFormula)> propertyData)
        {
            throw new NotImplementedException();
        }
    }
}
